package com.twu.biblioteca;

import com.twu.biblioteca.exception.InvalidSelectionException;
import com.twu.biblioteca.movie.MovieManager;
import com.twu.biblioteca.util.IO;
import com.twu.biblioteca.util.Validator;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


public class Client {
    private Library library;

    private void init() {
        createLibrary();
    }

    private void createLibrary() {
        List<Book> bookList = new ArrayList<Book>();
        Book bookOne = new Book("pro git", 1);
        Book bookTwo = new Book("gone with the wind", 2);
        Book bookThree = new Book("happiness", 3);
        bookList.add(bookOne);
        bookList.add(bookTwo);
        bookList.add(bookThree);

        BookManager bookManager = new BookManager();
        bookManager.initBooks(bookList);

        library = new Library(bookManager, new MovieManager());
        library.setValidator(new Validator());
    }

    public void run() throws IOException {
        init();
        System.out.print(Library.showOptions);
        while (!library.isQuit()) {
            String option = IO.readLine();
            try {
                library.excuteOption(option);
            } catch (InvalidSelectionException e) {
                IO.write(e.getMessage());
            }catch (Exception e) {
                IO.write(e.getMessage());
            }
        }
    }
}
